<?php

namespace App\Http\Middleware;
use App\Exceptions\BobException;
use Illuminate\Auth\Middleware\Authenticate as AuthenticateMiddleware;
class Authenticate extends AuthenticateMiddleware
{
    /**
     * 重定向
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\JsonResponse|string|null
     * @author Bob(bobcoder@qq.com)
     */
    protected function redirectTo($request)
    {
        return response()->json(['code' => '-1', 'msg' => '登陆过期，请重新登陆~'], 401);
    }

    /**
     * 登录过期或者未登录提示
     *
     * @param \Illuminate\Http\Request $request
     * @param array $guards
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
     * @throws BobException
     * @author Bob(bobcoder@qq.com)
     */
    protected function unauthenticated($request,array $guards)
    {
        throw new BobException(
            'Unauthenticated.', -1
        );
    }
}
